package com.wcfsy.wechat.wx.controller;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wcfsy.wechat.wx.entity.Tips;
import com.wcfsy.wechat.wx.util.JsonMessage;

@Controller
@RequestMapping("/cms/tips")
public class TipsController {
	private Logger logger = LoggerFactory
			.getLogger(TipsController.class);
 
	@RequestMapping({ "/today" })
	@ResponseBody
	public Object todayTips() {
		JsonMessage jm = new JsonMessage();
		try {
			/*
			 * User user = (User) SecurityManager
			 * .getSessionAttribute("SESSION_USER"); if (!user.isTipsRead()) {
			 * 
			 * }
			 */
			logger.info("查询tips");
			List<Tips> tipsList = new ArrayList<Tips>();
			Tips tips = new Tips();
			tips.setId(1);
			tips.setDisplayDateFrom(new Date());
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(tips.getDisplayDateFrom());
			calendar.add(Calendar.DATE, 3);
			tips.setDisplayDateTo(calendar.getTime());
			tipsList.add(tips);
			jm.setData(tipsList);
			jm.setSuccess("succeed");
		} catch (Exception e) {
			jm.setCode("01");
			jm.setMessage(e.toString());
			jm.setSuccess("error");
		}
		return jm;
	}

	@RequestMapping({ "/read" })
	@ResponseBody
	public Object readTips(long tipsId) {
		/*User user = (User) SecurityManager.getSessionAttribute("SESSION_USER");
		if (!user.isTipsRead()) {
			this.tipsService.readTips(user.getId(), new long[] { tipsId });
			user.setTipsRead(true);
		}*/
		logger.info("修改tips为已读");
		JsonMessage jm = new JsonMessage();
		jm.setSuccess("succeed");
		return jm;
	}
}
